<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>呼吸轮播图特效</title>
    <style>
    * {
        margin: 0;
        padding: 0;
    }

    ul {
        position: relative;
        list-style: none;
    }
    
    ul li {
        transition: all 0.5s ease 0s;
        position: absolute;
        width: 450px;
        height: 250px;
        background-color: red;
        text-align: center;
        line-height: 250px;
        font-size: 60px;
        opacity: 0;
    }
    ul li:first-child{
        opacity: 1;
    }

    ul li:nth-child(2n) {
        background-color: yellow;
    }

    img {
        height: 250px;
        width: 450px;
    }

    #box {
        position: relative;
        border: 1px solid black;
        width: 452px;
        height: 252px;
        margin: 50px auto;
    }

    #left {
        position: absolute;
        width: 50px;
        height: 50px;
        left: 20px;
        top: 50%;
        margin-top: -25px;
        background-color: skyblue;
    }

    #right {
        position: absolute;
        width: 50px;
        height: 50px;
        right: 20px;
        top: 50%;
        margin-top: -25px;
        background-color: skyblue;
    }
</style>
</head>
<body>
    <div id="box">
        <ul id="lb">
            <li>大</li>
            <li>帅</li>
            <li>哥</li>
            <li>在</li>
            <li>此</li>
            <li><img src="images/pan.jpg" alt=""></li>
        </ul>
        <div id="left"></div>
        <div id="right"></div>
    </div>
    <script>
        var box = document.getElementById('box');
        var lb = document.getElementById('lb');
        var left = document.getElementById('left');
        var right = document.getElementById('right');
        var li=lb.getElementsByTagName('li')
        var i=0;
        var lock=true;
        right.onclick=function(){
            if(!lock)return;
            lock=false;
            li[i].style.opacity='0';
            i++;
            if(i>5){
                i=0;
            }
            li[i].style.opacity='1';
            setTimeout(function(){
                lock=true;
            },500)
        }
        left.onclick=function(){
            if(!lock)return;
            lock=false;
            li[i].style.opacity='0';
            i--;
            if(i<0){
                i=5;
            }
            li[i].style.opacity='1';
            setTimeout(function(){
                lock=true;
            },500);
        }
    </script>
</body>
</html>